package beans;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author moloys
 */
public class DBMS {

    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/who_is_your_best_friend";
    Connection conn;

    private void estConnection() {
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, "root", "root");
            if (conn != null) {
                System.out.println("Connection Established");
            } else {
                System.out.println("Connection NOT Established");
            }
        } 
        catch (Exception e) {
            System.out.println("Exception caught:"+e);
        }
    }

    public int guid(String sql) {
        estConnection();
        int ru = 0;
        //<editor-fold defaultstate="collapsed" desc="comment">
        try {
            //</editor-fold>
            Statement st = conn.createStatement();
            ru = st.executeUpdate(sql);

        }
        catch (Exception e) {
           System.out.println("Exception caught:"+e);
        }
        return ru;
    }
    
    public ResultSet gSelect(String sql) {
        estConnection();
        ResultSet rs =null;
        try {
            Statement st = conn.createStatement();
            rs= st.executeQuery(sql);

        } 
        catch (Exception e) {
            System.out.println("Exception caught:"+e);
        }
        return rs;
    }
}
